/**
 * ____________________ *
 *  ____ ____ ____ _  _ *
 *  |___ [__] |--< |\/| *
 * ____________________ *
 *
 * THE CORM PROJECT
 *
 * This file may only be used in accordance with the
 * terms of the Academic Free License ("AFL") v. 3.0,
 * as published by the Open Software Initiative.  A
 * copy of this license is provided in this source
 * release, and may be viewed online at:
 *
 * (http://www.opensource.org/licenses/afl-3.0.php)
 */
package org.eremite.corm.crm;

import org.eremite.corm.party.address.Address;
import org.eremite.corm.party.relationship.PartyRelationship;
import org.eremite.corm.party.relationship.PartyRelationshipType;
import org.eremite.corm.party.relationship.PartyRole;
import org.eremite.corm.party.Party;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
public class Communication<P extends Party> extends PartyRelationship {

    @Id
    @GeneratedValue
    private long ID;

    private Date dateSent;
    private Date dateReceived;

    @Column(length=16384, nullable=false)
    private String content;
    
    private String outcome;

    @OneToMany(cascade = {
            CascadeType.PERSIST,
            CascadeType.REFRESH,
            CascadeType.MERGE})
    private Set<PartyRole<P>> participants = new HashSet<PartyRole<P>>();

    @ManyToOne(cascade = {
            CascadeType.PERSIST,
            CascadeType.REFRESH,
            CascadeType.MERGE})
    private Communication previous;

    @OneToMany(cascade = {
            CascadeType.PERSIST,
            CascadeType.REFRESH,
            CascadeType.MERGE},
            mappedBy="previous")
    private Set<Communication> next = new HashSet<Communication>();

    private Address fromAddress;

    @OneToMany(cascade = {
            CascadeType.PERSIST,
            CascadeType.REFRESH,
            CascadeType.MERGE})
    private Set<Address> toAddresses = new HashSet<Address>();

    @OneToMany(cascade = {
            CascadeType.PERSIST,
            CascadeType.REFRESH,
            CascadeType.MERGE})
    private Set<Action> actions = new HashSet<Action>();

    public Communication() {}

    public Communication(PartyRelationshipType type, PartyRole... roles) {
        super(type, roles);
    }

    public long getID() {
        return ID;
    }

    public void setID(long ID) {
        this.ID = ID;
    }

    public Date getDateSent() {
        return dateSent;
    }

    public void setDateSent(Date dateSent) {
        this.dateSent = dateSent;
    }

    public Date getDateReceived() {
        return dateReceived;
    }

    public void setDateReceived(Date dateReceived) {
        this.dateReceived = dateReceived;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getOutcome() {
        return outcome;
    }

    public void setOutcome(String outcome) {
        this.outcome = outcome;
    }

    public Set<PartyRole<P>> getParticipants() {
        return participants;
    }

    public Communication getPrevious() {
        return previous;
    }

    public void setPrevious(Communication previous) {
        this.previous = previous;
    }

    public Set<Communication> getNext() {
        return next;
    }

    public void setNext(Set<Communication> next) {
        this.next = next;
    }

    public Address getFromAddress() {
        return fromAddress;
    }

    public void setFromAddress(Address fromAddress) {
        this.fromAddress = fromAddress;
    }

    public Set<Address> getToAddresses() {
        return toAddresses;
    }

    public void setToAddresses(Set<Address> toAddresses) {
        this.toAddresses = toAddresses;
    }

    public Set<Action> getActions() {
        return actions;
    }

    public void setActions(Set<Action> actions) {
        this.actions = actions;
    }
}
